import 'package:flutter/material.dart';
import 'request/zj_home_request.dart';
import 'model/zj_home_model.dart';
import 'widget/zj_list_page_item.dart';

class ZJHomeContentListviewPage extends StatefulWidget {

  final String _type;
  final String _positionid;
  ZJHomeContentListviewPage(this._type, this._positionid, {Key key}) : super(key: key);

  @override
  State<ZJHomeContentListviewPage> createState() => _ZJHomeContentListviewPageState();
}

class _ZJHomeContentListviewPageState extends State<ZJHomeContentListviewPage> with AutomaticKeepAliveClientMixin {

  @override
  Widget build(BuildContext context) {
    backgroundColor: const Color(0xFFF3F5F7);
    return Column(children: <Widget>[
      Expanded(
          child: FutureBuilder(
            future: ZJHomeRequest.postHomePositionData(widget._type, "410100000000", widget._positionid, "1", "20"),
            builder: (BuildContext context,
                AsyncSnapshot<List<ZJHomePositionModel>> snapshot) {

                  if (!snapshot.hasData) return const Center(child: CircularProgressIndicator());
                  if (snapshot.error != null) return const Center(child: Text("请求失败"),);

                  final categories = snapshot.data;
                  return Scaffold(
                    backgroundColor: const Color(0xFFF3F5F7),
                    body: ListView.builder(
                        itemCount: categories.length,
                        itemBuilder: (ctx, index) {
                          return ZJListPageItem(categories[index]);
                        }
                    ),
                  );
            }
          )
      )
    ]);
  }

  @override
  bool get wantKeepAlive => true;

}